1. Technical Field
The present invention relates in general to a method and system for data processing and in particular to an improved method and system for counter level tracing. Still more particularly, the present invention relates to a method and system for tracing hardware counters by way of an interruption without introducing any overhead or modifying the code being counted.
2. Description of the Related Art
Most modern microprocessors, like members of the PowerPC family, provide hardware counters that can be programmed to count various events happening on the processor. To date, tools have been built around these facilities (usually and hereafter referenced as Performance Monitor) for application and operating system tuning. Such tools report counter values over complete runs of workloads to tune. In this mode, one resets the counters, programs the performance monitor to count the desired events, runs the workload to measure, and reads the counters after the workload has completed. This procedure is limited in that it only provides global information, i.e. from start to finish, without the possibility of figuring out which part of the workload is responsible for the counter increments.
Application Programming Interfaces (API) have also been built to collect counter information for portions of workloads. In this mode, one must add calls to API code just before and immediately after the execution of the portion of the workload to analyze. The former is to setup and start the counting and the latter is to stop the counting and retrieve the results. Those API calls can either be added directly to the source code if it is available or by way of instrumentation, i.e. dynamic insertion of code to divert normal execution path. This technique provides lower granularity results than the global counting of the previous approach, but at a big cost due to the overhead of the outside code necessary to control the counting. The overhead is what directly limits the obtainable granularity of the results.
Consequently, it would be desirable to provide an improved method and system that determines which part of a workload is responsible for counter increments of desired events without any overhead. In particular, it would be desirable to provide an improved method and system which utilizes a performance monitor facility and generates an exception after each branch instruction for gaining control at a basic block level for counting various events happening on a microprocessor.